package za.ac.wits.elen4010.capturetheflag;

import za.ac.wits.elen4010.capturetheflag.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class AndroidSignup extends Activity 
{
	
	private final EditText un = (EditText) findViewById(R.id.userNameEditText);
	private final EditText psw1= (EditText) findViewById(R.id.psw1EditText);
	private final EditText psw2= (EditText) findViewById(R.id.psw2EditText);
	private final EditText email= (EditText) findViewById(R.id.emailEditText);
	
	 public void onCreate(Bundle savedInstanceState) 
	    {
	        super.onCreate(savedInstanceState);
	        Bundle bundle = this.getIntent().getExtras();
	        String psw1Str = bundle.getString("psw");
	        final String unStr = bundle.getString("un");
	        
	        setContentView(R.layout.signup);
        	un.setText(unStr);
        	psw1.setText(psw1Str);
        	
	        Button submitButton = (Button) findViewById(R.id.submitButton);
	        submitButton.setOnClickListener(new View.OnClickListener() {
	            public void onClick(View v) {
	            	
	            	 if (un.getText().toString().length() < 3)
	            	 {
	            		 Toast.makeText(AndroidSignup.this, "User name invalid", Toast.LENGTH_SHORT).show();
	            		 return;
	            	 }
	            	 
	            	 String psw1Str = psw1.getText().toString();
	            	 String psw2Str = psw2.getText().toString();
	            	 
	            	 if (!psw1Str.equals(psw2Str))
	            	 {
	            		 Toast.makeText(AndroidSignup.this, "Password/'s dont match", Toast.LENGTH_SHORT).show();
	            		 return;
	            	 }
	            	 
	            	 if (psw1Str.length() < 5)
	            	 {
	            		 Toast.makeText(AndroidSignup.this, "Password invalid", Toast.LENGTH_SHORT).show();
	            		 return;
	            	 }
	            	
	                Intent intent = new Intent();
	                setResult(RESULT_OK, intent);
	                finish();
	            }

	        });
	    }
}
